#!/bin/bash

sleep 15 # RHR tends to tx on at :00

LOGFILE=`date +"/var/log/qrpbbb/%Y%m%d-%H%M.schedule"`

LOCK=/tmp/qrpbbb_schedule
trap 'rm -f ${LOCK} ; exit 1' 1 2 3 15

if /usr/lib/news/bin/shlock -p $$ -f ${LOCK}
then
    /root/qrpbbb/qrpbbb_schedule.py immediate 2>&1 >${LOGFILE}

    # if nothing done, remove
    n=`cat ${LOGFILE}|egrep -v "^Rescanning"\|"^$"|wc -l`
    if [ "x"$n == "x0" ]; then rm -f ${LOGFILE}; fi
fi
rm -f ${LOCK}
